
$(function(){
$('#endTime').datebox({
formatter:function(date){
	return date.getYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
}
});
$('#startTime').datebox({
formatter:function(date){
	return date.getYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
}
});
$("#searchid").linkbutton({
	 text:'查询',
	 iconCls:'icon-search'
});
 $('#grid').datagrid({
    title : '您所在的位置：资讯知识管理模块&nbsp;&nbsp;--&gt;&gt;&nbsp;&nbsp;资讯管理',
    width:1000,
    height:400,
    nowrap: false,
	striped: true,
	collapsible:false,
    url:'information_getInformationManage.shtml?type=2',
    frozenColumns:[[
	                {field:'ck',title:'选择',checkbox:true}
	                ]],
    columns:[[
			        {title:'基本信息',colspan:6},
					{field:'opt',title:'操作',width:150,align:'center', rowspan:2,
						formatter:function(value,rec){
						return '<span style="color:red"><span onclick=read("'+rec.id+'")>查看 </span><span onclick=Onmodify("'+rec.id+'")>修改</span> <span onclick=Ondelete("'+rec.id+'")>删除</span></span>';
						}
					}
				],[ 
					{field:'title',title:'标题',width:320},
					{field:'creatTimeStr',title:'发布时间',width:140,align:'center'},
				    {field:'content',title:'类型',width:130},
				    {field:'hot',title:'热点新闻',width:57,align:'center',formatter:function(value){if(value=="1") return "是";else return "否"}},
				    {field:'imgFlag',title:'图文资讯',width:57,align:'center',formatter:function(value){if(value=="1") return "是";else return "否"}},
				    {field:'isRecommend',title:'商家信息推送',width:60,align:'center',formatter:function(value){if(value=="1") return "是";else return "否"}}
				]],
				pagination:true,
				rownumbers:true,
				queryParams:{
				},
				toolbar:[{
					id:'btnadd',
					text:'添加资讯',
					iconCls:'icon-add',
					handler:function(){
						$(this).attr("href",'information_toInformationInfo.shtml?type=2&flag=1');
						
					}
				},'-',{
					id:'btnsave',
					text:'删除资讯',
					iconCls:'icon-save',
					handler:function(){
					    var  records= $('#grid').datagrid("getSelections");
					      var ids = '';
					    if(null==records || records==""){
					       alert('请选择要删除的记录');
					       return ;
					    }
					     for (var i = 0; i < records.length; i++) {
                        ids += records[i].id;
                        ids += ',';
                       }
                          var url1 ="information_delete.shtml";
                 $.ajax({
                   url: url1,
                   data: "idString="+ids.substring(0,ids.length-1),
                 success: function(msg){
                     
                     var obj=eval('('+msg+')');
                     var result=obj[0]["message"];
                     alert(result);
                     window.location.reload();
                    }
                  });
					}
				 },'-',{
					id : 'btnclose',
					text : '  &nbsp;关  闭',
					iconCls : 'icon-cancel',
					handler : function() {
						window.self.close();
					}
				}]
				}
				
		
              
);
    	 var page = $("#grid").datagrid("getPager").pagination("options");
			page.beforePageText = '第';
		  page.afterPageText = '页,共{pages}页';

			page.displayMsg = '显示从 {from} 至 {to} / {total} 的数据';
});
   

   function   onSearch(){
            var queryParams =$('#grid').datagrid("options").queryParams;
			queryParams.title=$("#title").val();
			queryParams.startTime=$("#stime").val();
			queryParams.endTime=$("#etime").val();
			queryParams.hotFlag=$("#hotFlag").val();
			queryParams.imgFlag=$("#imgFlag").val();
			queryParams.categoryId=$("#categoryId").val();
			queryParams.pcategoryId=$("#bigCategory").val();
			queryParams.isRecommend=$("#isRecommend").val();
			$('#grid').datagrid("reload");
   }
    function   Ondelete(id){ 
          if(id =="undefined") {alert("此条记录已删除");
             return;
          }
          if(confirm("确定删除此条信息吗?")){
                 var url1 ="information_delete.shtml";
             $.ajax({
                   url: url1,
                   data: "id="+id,
                 success: function(msg){
                     var obj=eval('('+msg+')');
                     var result=obj[0]["message"];
                     alert(result);
                     window.location.reload();
                 }
                });
          }
     }
     
     function read(id){
       window.location.href="information_toInformationInfo.shtml?flag=2&type=2&id="+id;
     }
      function Onmodify(id){
       window.location.href="information_toInformationInfo.shtml?flag=3&type=2&id="+id;
     }
     
     function getCategoryName(obj){
        return obj;
     }
     
     
     
function bigCategoryChange(){
	var bigCategoryValue = $("#bigCategory option:selected").val();
	if(bigCategoryValue != ""){
		$('#smallCategory').html('加载中... ...');
		$.get('../category/category_loadCategoryByPid.shtml?id='+bigCategoryValue+'&t='+new Date().getTime().toString(36),function(mes){
			var json = eval('('+mes+')');
			var str = '<select name="tgInformation.categoryId" id="categoryId" ><option value="">请选择</option>';
			for(var i = 0; i < json.length; i++){
				str += '<option value="'+json[i]['id']+'">'+json[i]['name']+'</option>';
			}
			str+='</select>';
			$('#smallCategory').html(str);
		})
	}
}

